package cloudspace.vm.javassist.tests;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javassist.ClassPool;

import junit.framework.TestCase;
import cloudspace.vm.javassist.AbstractCommand;
import cloudspace.vm.javassist.CommandInterface;
import cloudspace.vm.javassist.ConfigParser;

public class TranslatorConfigTest extends TestCase
{
	public void testCreateTranslatorConfig()
	{
		try
		{
			ConfigParser transConfig = new ConfigParser(new File(
					"src/configFiles/TranslatorConfig.conf"), new ClassPool());
			transConfig.autoUpdate();
		}
		catch (IOException e)
		{
			e.printStackTrace();
			fail("Bad Configuration File loaded into TransConfig");
		}
	}

	public void testGetCommands()
	{
		ConfigParser transConfig;
		try
		{
			transConfig = new ConfigParser(new File(
					"src/configFiles/TranslatorConfig.conf"), new ClassPool());
			List<CommandInterface> commandList = transConfig.getCommands();
			assertEquals("java.io.File(java.lang.String)", commandList.get(0)
					.getSignature());
			assertEquals(
					"{ $_ = $proceed(cloudspace.util.jassistwrappers.VirtualMachineMethods.toGlobalName($1)); "
							+ "cloudspace.util.jassistwrappers.VirtualMachineMethods.logUserPassedString((java.io.File)$0,$1);}",
					commandList.get(0).getReplacement());
			//assertEquals(AbstractCommand.TranslationType.REPLACE, commandList.get(0)
			//		.getTranslationType());
			assertEquals(AbstractCommand.SignatureType.CONSTRUCTORCALL, commandList
					.get(0).getSignatureType());
		}
		catch (IOException e)
		{
			e.printStackTrace();
			fail("Bad Configuration File loaded into TransConfig");
		}
/*		catch (MalformedCommandException ex)
		{
			ex.printStackTrace();
			fail("Commands loaded improperly");
		}*/

	}
}
